package cn.dansj.service.Impl;

import cn.dansj.entity.CalendarEvent;
import cn.dansj.repository.CalendarEventRepository;
import cn.dansj.service.CalendarEventService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CalendarEventServiceImpl implements CalendarEventService {
    private final CalendarEventRepository calendarEventRepository;

    public CalendarEventServiceImpl(CalendarEventRepository calendarEventRepository) {
        this.calendarEventRepository = calendarEventRepository;
    }

    @Override
    public List<CalendarEvent> getCalendarEvent(String userId) {
        return calendarEventRepository.findAllByUserId(userId);
    }

    @Override
    public void save(CalendarEvent calendarEvent) {
        calendarEventRepository.save(calendarEvent);
    }

    @Override
    public void save(List<CalendarEvent> calendarEvents) {
        calendarEventRepository.saveAll(calendarEvents);
    }

    @Override
    @Transactional
    public void delete(String sequence) {
        calendarEventRepository.deleteAllBySequence(sequence);
    }
}
